home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMIBEST4.ADF
/
AmigaBasicStuff
/
BasicSorts
/
InsertionSort
< prev
next >
Wrap
Text File
|
1987-07-22
|
657b
|
30 lines
sub InsertionSort ( x$(), n% ) static
' Sort x(1..n) , n > 1
' Invariant : x(1..i-1) is sorted
'
' An O(n^2) algorithm...
'
'
FOR i = 2 TO n%
j=i
t$=x$(j)
Jail:
IF j <= 1 OR x$(j-1) <=t$ THEN HaveATogaParty
x$(j) = x$(j-1)
j = j - 1
GOTO Jail
HaveATogaParty:
x$(j) = t$
NEXT
'
' Algorithm from Programming Pearls by John Bentley
' from AT&T Bell Laboratories.
'
' Implemented in AmigaBasic by Gregory A. Kendall
' from Brendallson Software.
'
end sub